﻿
using System.Drawing;
using System.ComponentModel;
using Tools;

namespace ShapeManager
{
    /// <summary> 形状对象：创建的形状参数 </summary>
    public class Shape
    {
        #region 字段、属性
        #region 常量
        // 序列化的条目名称
        /// <summary> 序列化颜色 </summary>
        protected const string entryColor = "Color";
        /// <summary> 序列化线宽 </summary>
        protected const string entryPenWidth = "borderWidth";
        #endregion

        #region 字段
        private int id;
        private string _description = "形状描述";    //形状描述
        protected RectangleF _rectangleF;            //形状（实际矩形）区域
        protected Color _backColor = Color.Blue;     //填充颜色
        protected Color _handleColor = Color.Orange; //手柄颜色
        protected Color _selectedColor = Color.Blue; //选中时的颜色
        protected Color _interestColor = Color.Red;  //感兴趣颜色，不感兴趣时使用
        protected Color _enhanceColor = Color.Green; //增强颜色
        protected Color _borderColor = Color.Blue; //增强颜色
        protected float _borderWidth = 0;            //边缘线宽
        protected byte _alpha = 20;                  //透明度            
        protected int _handleSize = 5;               //手柄的视觉大小
        protected int _handleOutSize = 7;           //手柄外区域大小(比视觉大)
        protected bool _isSelected = true;           //选中状态
        protected bool _isInterest = true;           //感兴趣状态
        protected bool isRotating = false;           //是否旋转
        protected ShapeType _type = ShapeType.Pointer;  //形状类型
        protected ShapeHandleType _handleType;       //形状手柄类型    
        protected float _angle = 0f;                 //形状手柄类型
        #endregion

        #region 属性
        /// <summary> 形状名称 </summary>
        [Category("用户属性")]
        [Description("形状名称")]
        public string Name { get => id.ToString(); }
        /// <summary> 形状描述 </summary>
        [Category("用户属性")]
        [Description("形状描述")]
        public string Description { get => _description; set => _description = value; }
        /// <summary> 形状填充的背景颜色 </summary>
        [Category("用户属性")]
        [Description("形状填充的背景颜色")]
        public Color BackColor { get => _backColor; set => _backColor = value; }
        /// <summary> 形状手柄填充的颜色 </summary>
        [Category("用户属性")]
        [Description("形状手柄填充的颜色")]
        public Color HandleColor { get => _handleColor; set => _handleColor = value; }
        /// <summary> 选中形状时填充的颜色 </summary>
        [Category("用户属性")]
        [Description("选中形状时填充的颜色")]
        public Color SelectedColor { get => _selectedColor; set => _selectedColor = value; }
        /// <summary> 选中形状时填充的颜色 </summary>
        [Category("用户属性")]
        [Description("感兴趣颜色，感兴趣状态为False时的背景色")]
        public Color InterestColor { get => _interestColor; set => _interestColor = value; }

        /// <summary> 选中形状时填充的颜色 </summary>
        [Category("用户属性")]
        [Description("设置增强模式时显示的颜色")]
        public Color EnhanceColor { get => _enhanceColor; set => _enhanceColor = value; }
        /// <summary> 选中形状时填充的颜色 </summary>
        [Category("用户属性")]
        [Description("设置增强模式时显示的颜色")]
        public Color BorderColor { get => _borderColor; set => _borderColor = value; }
        /// <summary> 边缘线宽</summary>
        [Category("用户属性")]
        [Description("边缘线宽")]
        public float BorderWidth { get => _borderWidth; set => _borderWidth = value; }
        /// <summary> 边缘线宽</summary>
        [Category("用户属性")]
        [Description("边缘线宽")]
        public float Angle { get => _angle; set => _angle = value; }

        /// <summary> 透明度</summary>
        [Category("用户属性")]
        [Description("透明度")]
        public byte Alpha { get => _alpha; set => _alpha = value; }
        /// <summary> 手柄大小</summary>
        [Category("用户属性")]
        [Description("手柄大小")]
        public int HandleSize
        {
            get => _handleSize;
            set
            {
                if (_handleSize != value)
                {
                    _handleSize = value;
                    HandleOutSize = value + 3;
                }
            }
        }
        /// <summary> 手柄扩增后大小</summary>
        [Category("用户属性")]
        [Description("手柄扩增后大小")]
        public int HandleOutSize
        {
            get => _handleOutSize;
            set
            {
                if (_handleOutSize != value)
                {
                    _handleOutSize = value;
                    _handleSize = value - 3;
                }
            }
        }
        /// <summary> 选中状态</summary>
        [Category("用户属性")]
        [Description("选中状态")]
        public bool IsSelected { get => _isSelected; set => _isSelected = value; }
        /// <summary> 感兴趣状态</summary>
        [Category("用户属性")]
        [Description("感兴趣状态")]
        public bool IsInterest { get => _isInterest; set => _isInterest = value; }
        /// <summary> 形状类型 </summary>
        [Category("用户属性")]
        [Description("形状类型")]
        public ShapeType Type { get => _type; set => _type = value; }
        /// <summary> 旋转使能 </summary>
        [Category("用户属性")]
        [Description("旋转使能")]
        public virtual bool IsRotating { get => isRotating; set => isRotating = value; }
        /// <summary> 手柄类型 </summary>
        [Category("用户属性")]
        [Description("手柄类型")]
        public ShapeHandleType HandleType { get => _handleType; set => _handleType = value; }
        /// <summary> 形状区域 </summary>
        [Category("用户属性")]
        [Description("形状区域")]
        public RectangleF Region { get => _rectangleF; set => _rectangleF = value; }
        /// <summary> 形状位置 </summary>
        [Category("用户属性")]
        [Description("形状位置")]
        public PointF Location { get => _rectangleF.Location; set => _rectangleF.Location = value; }
        /// <summary> 形状位置 </summary>
        [Category("用户属性")]
        [Description("所在位置的X方向")]
        public float X { get => _rectangleF.X; set => _rectangleF.X = value; }
        /// <summary> 形状位置 </summary>
        [Category("用户属性")]
        [Description("所在位置的Y方向")]
        public float Y { get => _rectangleF.Y; set => _rectangleF.Y = value; }
        /// <summary> 形状位置 </summary>
        [Category("用户属性")]
        [Description("形状宽度")]
        public float Width { get => _rectangleF.Width; set => _rectangleF.Width = value; }
        /// <summary> 形状位置 </summary>
        [Category("用户属性")]
        [Description("形状高度")]
        public float Height { get => _rectangleF.Height; set => _rectangleF.Height = value; }
        /// <summary> 形状位置 </summary>
        [Category("用户属性")]
        [Description("形状大小")]
        public SizeF Size { get => _rectangleF.Size; set => _rectangleF.Size = value; }

        /// <summary> 手柄数量 </summary>
        [Category("用户属性")]
        [Description("手柄个数")]
        public virtual int HandleCount { get => 0; }
        /// <summary> 对象ID </summary>
        [Category("用户属性")]
        [Description("对象ID")]
        public int ID { get => id; set => id = value; }
        #endregion
        #endregion
    }

    #region 枚举类型
    /// <summary> 手柄类型 </summary>
    public enum ShapeHandleType
    {
        None,
        [Description("旋转")]
        Rotation,
        [Description("中心")]
        Center,
        [Description("内部")]
        Inner,
        [Description("左")]
        Left,
        [Description("上")]
        Top,
        [Description("右")]
        Right,
        [Description("下")]
        Bottom,
        [Description("左上")]
        TopLeft,
        [Description("右上")]
        TopRight,
        [Description("左下")]
        BottomLeft,
        [Description("右下")]
        BottomRight
    }
    /// <summary> 形状类型  </summary>
    public enum ShapeType
    {
        [Description("矩形")]
        Pointer,
        [Description("矩形")]
        Rectangle,
        [Description("方向矩形")]
        RectangleR,
        [Description("圆形")]
        Circle,
        [Description("椭圆形")]
        Ellipse,
        [Description("线形")]
        Line,
        [Description("多边形")]
        Polygon,
        [Description("Number")]
        NumberOfDrawTools
    }
    /// <summary> 形状操作模式 </summary>
    public enum ShapeOperateMode
    {
        /// <summary> None</summary>
        [Description("None")]
        None,
        /// <summary>绘制</summary>
        [Description("绘制")]
        Drawing,
        /// <summary>选中</summary>
        [Description("选中")]
        Selected,
        /// <summary>移动</summary>
        [Description("移动")]
        Move,
        /// <summary>缩放</summary>
        [Description("缩放")]
        Scaled,
        /// <summary>旋转</summary>
        [Description("旋转")]
        Rotote,
        /// <summary>调整大小</summary>
        [Description("调整大小")]
        Resize,
    }
    #endregion
}
